package org.darkforest.common.services.impl;

import org.darkforest.dao.mapper.WaybillMapper;
import org.darkforest.common.services.ModuleService;
import org.darkforest.model.Waybill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by liu on 15/1/18.
 */
@Service("moduleService")
public class ModuleServiceImpl implements ModuleService {
    @Autowired
    WaybillMapper waybillMapper;

    public List selectAllBill(){
        return waybillMapper.selectAllBill();
    }
    public List selectAllUnUsedBill(){
        return waybillMapper.selectAllUnUsedBill();
    }

    public int insertBill(Waybill bill){
        if(bill.getWaybillName().indexOf(bill.getExpressName())<0){
            bill.setWaybillName(bill.getExpressName()+bill.getWaybillName()); //模板名称 默认快递公司+自定义名称
        }

        return waybillMapper.insertSelective(bill);
    }

    public int updateBill(Waybill waybill){
        return waybillMapper.updateByPrimaryKeySelective(waybill);
    }

    public Waybill selectById(int waybillId){
        return waybillMapper.selectByPrimaryKey(waybillId);
    }

    public int updateUnbind(Waybill record){
        return waybillMapper.updateUnbind(record);
    }

   public int  delectBill(int id){
       return waybillMapper.deleteByPrimaryKey(id);
   }

    /**
     * 根据添加查询运单模板
     *
     * @param waybill
     * @return
     */
    @Override
    public List<Waybill> findListByCondition(Waybill waybill) {
        return waybillMapper.selectByCondition(waybill);
    }

    public Waybill selectByCondition(Waybill record) {
        record.setResultList(waybillMapper.selectByCondition(record));
        return record;
    }

}
